package com.jiangyifen.robot.core;

import java.io.File;

import com.jiangyifen.robot.core.asr.AliyunASRClient;
import com.jiangyifen.robot.core.session.RobotSession;
import com.jiangyifen.robot.core.sipphone.SipPhoneClient;
import com.jiangyifen.robot.entity.ChatNodeEntity;
import com.jiangyifen.robot.entity.RobotYunXiaoMiEntity;
import com.jiangyifen.robot.sdk.event.HumanSentenceCompleteEvent;
import com.jiangyifen.robot.sdk.event.HumanSilenceEvent;
import com.jiangyifen.robot.sdk.event.HumanSpeakingByteStreamEvent;
import com.jiangyifen.robot.sdk.event.HumanSpeakingEvent;
import com.jiangyifen.robot.sdk.event.RobotSayNodeEvent;
import com.jiangyifen.robot.sdk.event.RobotSentenceCompleteEvent;
import com.jiangyifen.robot.sdk.event.RobotSpeakingEvent;
import com.jiangyifen.robot.sdk.event.SipCalleePickupEvent;
import com.jiangyifen.robot.sdk.event.SipErrorEvent;
import com.jiangyifen.robot.sdk.event.SipIncomingCallEvent;
import com.jiangyifen.robot.sdk.event.SipRegisterFailedEvent;
import com.jiangyifen.robot.sdk.event.SipRegisterSuccessfulEvent;
import com.jiangyifen.robot.sdk.event.SipRegisteringEvent;
import com.jiangyifen.robot.sdk.event.SipRemoteHangupEvent;
import com.jiangyifen.robot.sdk.event.SipRingingEvent;

public interface Robot {
	
	public Long getId();
	public RobotYunXiaoMiEntity getRobotEntity();
	
	public SipPhoneClient getSipPhoneClient();
	public AliyunASRClient getAliyunASRClient();
	
	public RobotSession getNewSession();
	public RobotSession getCurrentSession();
	
	public long getLastSilenceTimestamp();
	public void setLastSilenceTimestamp(long lastSilenceTimestamp);
	
	public boolean isRegisterSuccessful();
	public void setRegisterSuccessful(boolean registerSuccessful);

	public boolean isCalling();
	public void setCalling(boolean calling);
	

	///////////////// 主动控制 /////////////////////

	/**
	 * 机器人软电话register
	 */
	public void register();
	
	/**
	 * 机器人软电话unregister
	 */
	public void unregister();
	
	/**
	 * 发起呼叫
	 * 
	 * @param phoneNumber 需要呼叫的电话号码
	 */
	public String call(String phoneNumber);

	//TODO 需要vmw支持
	public String originate();
	
	/**
	 * 发送DTMF信号
	 * 
	 * @param digit dtmf值（电话键盘的按键，0123456789*#）
	 */
	public void dtmf(final char digit); 
	
	/**
	 * 拒接
	 */
	public void rejectCall();
	
	/**
	 * 挂断当前通话
	 */
	public void hangup();
	
	/**
	 * 接听当前通话
	 */
	public void answer();
	
	/**
	 * 机器人说话
	 * @param chatNodeEntity
	 */
	public void sayChatNode(ChatNodeEntity chatNodeEntity);
	
	/**
	 * 机器人说话
	 * @param filePath 本地语音文件路径
	 * @param canBeInterrupt 是否可以被打断
	 */
	public void sayFile(String filePath, Boolean canBeInterrupt);
	
	/**
	 * 机器人说话
	 * @param file 本地语音文件对象
	 * @param canBeInterrupt 是否可以被打断
	 */
	public void sayFile(File file, Boolean canBeInterrupt);
	
	/**
	 * 机器人说话
	 * @param canBeInterrupt 是否可以被打断
	 * @param url 远程语音文件url
	 */
	public void sayUrl(String url, Boolean canBeInterrupt);
	
	/**
	 * 机器人说话
	 * @param text 说话内容
	 * @param canBeInterrupt 是否可以被打断
	 */
	public void sayText(String text, Boolean canBeInterrupt);

	/**
	 * 机器人打断
	 */
	public void stopTalking();
	
	
	/////////////////////////  被动回调  ///////////////////////////////////////
	

	/**
	 * 当检测到对端人类说完一整句话时，触发此回调
	 * 
	 * @param event
	 */
	public void onHumanSentenceComplete(HumanSentenceCompleteEvent event);
	
	/**
	 * 当机器人说完话后，对面的人类长时间没有说话，触发此回调
	 * 
	 * @param event
	 */
	public void onHumanSilence(HumanSilenceEvent event);
	
	/**
	 * 当检测到对端人类开始说话时，触发此回调
	 * 
	 * @param event
	 */
	public void onHumanSpeaking(HumanSpeakingEvent event);
	
	/**
	 * 人类说话的语音流数据会持续不断地发送到这个接口
	 * 
	 * @param event
	 */
	public void onHumanSpeakingByteStream(HumanSpeakingByteStreamEvent event);
	
	
	
	
	/**
	 * 当机器人自己说完一句话时，触发此回调
	 * 
	 * @param event
	 */
	public void onRobotSentenceComplete(RobotSentenceCompleteEvent event);
	
	/**
	 * 机器人说话中，这个接口会持续被调用
	 * 
	 * @param event
	 */
	public void onRobotSpeaking(RobotSpeakingEvent event);
	
	/**
	 * 机器人说了某个节点
	 * 一般用于记录关键节点，触发业务系统的某个动作，比如记录投诉或重要客户等
	 * 
	 * @param event
	 */
	public void onRobotSayNode(RobotSayNodeEvent event);
	

	
	
	
	///  sip events ////
	
	public void onSipRegistering(SipRegisteringEvent event);
	public void onSipRegisterSuccessful(SipRegisterSuccessfulEvent event);
	public void onSipRegisterFailed(SipRegisterFailedEvent event);
	
	/**
	 * 机器人呼出，对方正在振铃中
	 */
	public void onSipRinging(SipRingingEvent event);
	/**
	 * 有电话呼入
	 */
	public void onSipIncomingCall(SipIncomingCallEvent event);
	public void onSipCalleePickup(SipCalleePickupEvent event);
	public void onSipRemoteHangup(SipRemoteHangupEvent event);
	
	public void onSipError(SipErrorEvent event);
	
}
